<template>
  <DialogAntD ref="dialog"
              :not-allowed="notAllowed"
              :attrs="attrs"
              :data-list.sync="dataList"
              type="unit"
              :pro="{
                id: 'id',
                name: 'name'
              }">
  </DialogAntD>
</template>

<script>

import DialogAntD from './components/DialogAntD.vue'
import unitUserMixins from './mixins/unitUserMixins'
import PropTypes from '@zh/common-utils/prop-types'

import clone from 'clone'

import { getUnitListByParentIdAndNeedUnitType, getTreeUnitListByUserIds } from './../api/select'

export default {
  name: 'ZUnitPicker',
  components: { DialogAntD },
  mixins: [unitUserMixins],
  props: {
    needUnitType: {
      type: String,
      default: '1'
    }
  },
  data () {
    return {
      attrs: {
        title: '请选择机构',
        type: 'unit'
      },
      notAllowed: [],
      labelDataList: {
        '0': {
          name: '最顶级'
        }
      }
    }
  },
  created () {
  },
  methods: {
    open () {
      // 初始化数据
      this.$refs.dialog.breadcrumbLists = [this.topUnitId]
      this.loadNode(this.topUnitId, this.needUnitType)
      this.$refs.dialog.tagLists = clone(this.newValue)
      this.$refs.dialog.openDialog()
    },
    loadNode (parentId) {
      this.listLoading = true
      getUnitListByParentIdAndNeedUnitType(parentId).then((data) => {
        if (data) {
          this.dataList = []
          const UnitId = []
          this.notAllowed = UnitId
          data.forEach((item) => {
            this.dataList.push(item.id)
            this.labelDataList[item.id] = item
          })
          this.listLoading = false
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
</style>